package com.bkgy.controller.tcmEnSpeedRules.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bkgy.controller.tcmEnSpeedRules.entity.TcmEnSpeedRules;
import com.bkgy.controller.tcmEnSpeedRules.entity.pdo.TcmEnSpeedRulesQueryReq;
import com.bkgy.controller.tcmEnSpeedRules.mapper.ITcmEnSpeedRulesMapper;
import com.bkgy.controller.tcmEnSpeedRules.service.ITcmEnSpeedRulesService;
import com.bkgy.sys.common.entity.ResultData;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class TcmEnSpeedRulesServiceImpl extends ServiceImpl<ITcmEnSpeedRulesMapper,TcmEnSpeedRules> implements ITcmEnSpeedRulesService {

	@Override
	public ResultData<String> saveTcmEnSpeedRules(TcmEnSpeedRules obj) {
		boolean res = false;
		try {
			obj.setUpdateTime(new Date());
			res = save(obj);
		} catch (Exception e) {
			e.printStackTrace();
			log.error(e.getMessage());
		}
		return ResultData.ResultDataSuccess(res ? "SUCCESS" : "FAIL");
	}

	@Override
	public ResultData<String> updateTcmEnSpeedRules(TcmEnSpeedRules obj) {
		obj.setUpdateTime(new Date());
		boolean res = updateById(obj);
		return ResultData.ResultDataSuccess(res ? "SUCCESS" : "FAIL");
	}

	@Override
	public ResultData<String> deleteTcmEnSpeedRules(TcmEnSpeedRules obj) {
		boolean res = removeById(obj.getId());
		return ResultData.ResultDataSuccess(res ? "SUCCESS" : "FAIL");
	}

	@Override
	public ResultData selectPage(TcmEnSpeedRulesQueryReq req) {
		Page<TcmEnSpeedRules> p = new Page<>(req.getPageIndex(), req.getPageSize());
		IPage<TcmEnSpeedRules> data = page(p);
		return ResultData.ResultDataSuccess(data.getRecords(), (int) data.getTotal());
	}
}
